package com.hdyg.sixg.adapter;

import android.support.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hdyg.sixg.R;
import com.hdyg.sixg.entry.OrderBean;
import com.hdyg.sixg.fragment.TransChildFragment;

import java.util.List;

/**
 * @author CZB
 * @describe 交易中心挂售适配器
 * @time 2019/3/20 14:22
 */
public class TransChildAdapter extends BaseQuickAdapter<OrderBean.ListBean, BaseViewHolder> {
    private int TYPE;
    private String str1,str2,str3,str4;
    public TransChildAdapter(int layoutResId, @Nullable List<OrderBean.ListBean> data,int TYPE) {
        super(layoutResId, data);
        this.TYPE = TYPE;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBean.ListBean item) {
        helper.addOnClickListener(R.id.bt_buy);
        helper.setText(R.id.tv_phone,item.getPhone());//手机号码

        if (TYPE == TransChildFragment.ORDER_ALL) {
            str1 = String.format(mContext.getResources().getString(R.string.trans_item_1),item.getSingle_price());//估值
            str2 = String.format(mContext.getResources().getString(R.string.trans_item_2),item.getAmount());//总量
            str3 = String.format(mContext.getResources().getString(R.string.trans_item_3),item.getRest_amount());//剩余
            str4 = String.format(mContext.getResources().getString(R.string.trans_item_4),item.getSell_amount());//已卖
            helper.setText(R.id.bt_buy,mContext.getResources().getString(R.string.trans_item_5));//购买
        } else if (TYPE == TransChildFragment.ORDER_HANG_UP) {
            str1 = String.format(mContext.getResources().getString(R.string.trans_item_1),item.getSingle_price());//估值
            str2 = String.format(mContext.getResources().getString(R.string.trans_item_2),item.getAmount());//总量
            str3 = String.format(mContext.getResources().getString(R.string.trans_item_3),item.getRest_amount());//剩余
            str4 = String.format(mContext.getResources().getString(R.string.trans_item_4),item.getSell_amount());//已卖
            if ("1".equals(item.getStatus())){
                //已下架
                helper.setText(R.id.bt_buy,mContext.getResources().getString(R.string.trans_item_6_2));
                helper.setBackgroundRes(R.id.bt_buy,R.mipmap.trans_btn_bg_gray);
            }else {
                //未下架
                helper.setText(R.id.bt_buy,mContext.getResources().getString(R.string.trans_item_6));
                helper.setBackgroundRes(R.id.bt_buy,R.mipmap.trans_btn_bg);
            }
        } else if (TYPE == TransChildFragment.ORDER_BUY) {
            str1 = String.format(mContext.getResources().getString(R.string.trans_item_1),item.getPrice());//估值
            str2 = String.format(mContext.getResources().getString(R.string.trans_item_2_1),item.getAmount());//数量
            str3 = String.format(mContext.getResources().getString(R.string.trans_item_3_1),item.getTotal_price());//总估值
            str4 = item.getPay_status();//状态
            helper.setTextColor(R.id.tv_remaining,mContext.getResources().getColor(R.color.white));
            helper.setTextColor(R.id.tv_sell,mContext.getResources().getColor(R.color.main_color));
            helper.setText(R.id.bt_buy,mContext.getResources().getString(R.string.trans_item_7));//详情
        } else if (TYPE == TransChildFragment.ORDER_SELL) {
            str1 = String.format(mContext.getResources().getString(R.string.trans_item_1),item.getPrice());//估值
            str2 = String.format(mContext.getResources().getString(R.string.trans_item_2_1),item.getAmount());//数量
            str3 = String.format(mContext.getResources().getString(R.string.trans_item_3_1),item.getTotal_price());//总估值
            str4 = item.getPay_status();//状态
            helper.setTextColor(R.id.tv_remaining,mContext.getResources().getColor(R.color.white));
            helper.setTextColor(R.id.tv_sell,mContext.getResources().getColor(R.color.main_color));
            helper.setText(R.id.bt_buy,mContext.getResources().getString(R.string.trans_item_7));//详情
        }
        helper.setText(R.id.tv_valuation,str1);
        helper.setText(R.id.tv_all_count,str2);
        helper.setText(R.id.tv_remaining,str3);
        helper.setText(R.id.tv_sell,str4);
    }
}
